<script setup>
import {
    Edit,
    Delete
} from '@element-plus/icons-vue'
import { ref,onMounted } from 'vue'

const studentin3 = ref([
    {
        "studentId": "",
        "sname": "",
        "sgrade": "",
        "politicalScore": "",
        "researchScore":"",
        "socialScore":"",
        "sumScore":"",
        "calScore":"",
        "isqualified": "",
        "award":""
    }
])
const ruleList = ref([])//存储规则列表数据
const selectedYear = ref('')//选中的规则年份
//声明一个异步的函数 页面加载完毕之后 调用articleCategoryListService方法来获取所有文章的分类列表 调用这个函数时同步等待他返回的结果
import {studentin3ListService,calculate} from '@/api/studentin3.js'
import{rulesListService} from '@/api/rules.js'
const studentin3List = async()=>{
    let result = await studentin3ListService();
    studentin3.value=result.data//result.data列表数据 赋值给student
}
studentin3List();//调用


//获取规则列表
const getRules = async()=>{
    let result = await rulesListService();
    ruleList.value=result.data
}
getRules();
//计算成绩
const calculateScore = async()=>{
    if(!selectedYear.value){
        alert('请输入年份');
        return;
    }
    await calculate(selectedYear.value);
    await studentin3List();//重新获取研二学生
}





</script>

<template>
  <el-card class="page-container">
    <template #header>
      <div class="header">
        <span>研三奖学金</span>
        <div>
          <!-- 规则年份选择下拉框 -->
          <el-select v-model="selectedYear" placeholder="请选择规则年份">
            <el-option 
              v-for="rule in ruleList" 
              :key="rule.id" 
              :label="rule.year" 
              :value="rule.year">
            </el-option>
          </el-select>
          <!-- 计算成绩按钮 -->
          <el-button type="primary" @click="calculateScore">根据所选年份计算成绩</el-button>
        </div>
      </div>
    </template>
    <el-table :data="studentin3" style="width: 100%">
      <el-table-column label="序号" width="100" type="index"> </el-table-column>
      <el-table-column label="学生学号" prop="studentId"></el-table-column>
      <el-table-column label="姓名" prop="sname"></el-table-column>
      <el-table-column label="年级" prop="sgrade"></el-table-column>
      <el-table-column label="思政成绩" prop="politicalScore"></el-table-column>
      <el-table-column label="科研成绩" prop="researchScore"></el-table-column>
      <el-table-column label="社会成绩" prop="socialScore"></el-table-column>
      <el-table-column label="总成绩" prop="sumScore"></el-table-column>
      <el-table-column label="计算后成绩" prop="calScore"></el-table-column>
      <el-table-column label="奖学金资格" prop="isqualified"></el-table-column>
      <el-table-column label="是否获奖" prop="award"></el-table-column>
      <template #empty>
        <el-empty description="没有数据" />
      </template>
    </el-table>
  </el-card>
</template>

<style lang="scss" scoped>
.page-container {
    min-height: 100%;
    box-sizing: border-box;

    .header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
}
</style>